<?php
function dbconnect()
{
$connect = mysql_connect('localhost','root','');
mysql_select_db("ajaxversion4");
error_reporting(E_ALL ^ E_NOTICE);
}
function selectquery($tablename)
{
$selectadmin = "SELECT * from .$tablename";
$admincheck = mysql_query($selectadmin);
$rows = array();
while($row = mysql_fetch_array($admincheck))
{
$rows[]=$row;
}
return $rows;
}
function insertquery($tablename,$insertvalue)
{
	$field1 = "";
	$field2 = "";
	$i=1; $count = count($insertvalue);
	foreach($insertvalue as $key=>$value)
	{
	if($i==$count)
	{
	$field1.=$key;
	$field2.="'".$value."'";
	}
	else
	{
	$field1.=$key.",";
	$field2.="'".$value."'". ",";
	}
	$i++;
	}
	
	$insert = "INSERT into .$tablename($field1) 
	values($field2)";
	//print_r($insert);
	$insertresult = mysql_query($insert);
}

function deletequery($tablename,$fieldname,$fieldid)
{
$delete = "DELETE FROM $tablename WHERE $fieldname='$fieldid'";
//echo $delete;exit;
$de = mysql_query($delete);
}

function updatequery($tablename,$updatevalue,$name,$id)
{
$filed ="";
$i=1; $count=count($updatevalue);
foreach($updatevalue as $key=>$value)
{
if($i==$count)
{
$filed.=$key."="."'".$value."'";
}
else
{
$filed.=$key."="."'".$value."'".",";
}
$i++;
}
$update = "UPDATE $tablename SET $filed WHERE $name='$id'";
$updatevalue = mysql_query($update);
}

?>